using LANLauncher.Properties;
using Microsoft.Win32;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Resources;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Threading;
using System.Windows.Forms;
using System.Text;

namespace LANLauncher
{
	public class LauncherForm : Form
	{
		private string commandlineArgs;

		private Dictionary<string, string> languages = new Dictionary<string, string>();

		private LANLauncher.Settings settings = new LANLauncher.Settings();

		private bool launchGameButtonInstallsGame;

		private string gameInstallDir = "";

		private string currentGameVersion = "";

		private string socialClubInstallDir = "";

		private string socialClubVersion = "";

		private Options optionsForm;

		private Thread patchCheckThread;

		private bool suppress;

		private IContainer components;

		private Button launchGameButton;

		private Button optionsButton;

		private Button quitButton;

		private PictureBox pictureBox1;

		private ComboBox languagesComboBox;

		private Button readmeButton;

		private ToolTip toolTip;

		private Label LANGUAGE;

		private ComboBox keyboardComboBox;

		private Label KEYBOARD;

		private Label versionLabel;

		private Label gamePatchStatusLabel;

		private Label scPatchStatusLabel;


    internal static class NativeMethods
    {
        [Flags()]
        public enum ProcessAccess : int
        {
            AllAccess = CreateThread | DuplicateHandle | QueryInformation | SetInformation | Terminate | VMOperation | VMRead | VMWrite | Synchronize,
            CreateThread = 0x2,
            DuplicateHandle = 0x40,
            QueryInformation = 0x400,
            SetInformation = 0x200,
            Terminate = 0x1,
            VMOperation = 0x8,
            VMRead = 0x10,
            VMWrite = 0x20,
            Synchronize = 0x100000
        }

        [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
        internal static extern IntPtr LoadLibraryA(string lpFileName);

        [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        internal static extern UIntPtr GetProcAddress(IntPtr hModule, string procName);

        [DllImport("kernel32.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        internal static extern bool FreeLibrary(IntPtr hModule);

        [DllImport("kernel32.dll")]
        internal static extern IntPtr OpenProcess(ProcessAccess dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, int dwProcessId);

        [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
        internal static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress,
        uint dwSize, UInt32 flAllocationType, UInt32 flProtect);

        [DllImport("kernel32.dll", SetLastError = true)]
        internal static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out UIntPtr lpNumberOfBytesWritten);

        [DllImport("kernel32.dll")]
        internal static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, UIntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, out IntPtr lpThreadId);

        [DllImport("kernel32.dll", SetLastError = true)]
        internal static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, out int lpNumberOfBytesRead);
    }
        public static Boolean InjectDLL(String DLL, Process Proc)
        {
            UIntPtr bWritten;
            IntPtr hThread;

            byte[] DLLName = new ASCIIEncoding().GetBytes(DLL);

            IntPtr hKernel = NativeMethods.LoadLibraryA("kernel32.dll");
            UIntPtr LoadLib = NativeMethods.GetProcAddress(hKernel, "LoadLibraryA");
            NativeMethods.FreeLibrary(hKernel);

            if (LoadLib == UIntPtr.Zero)
                return false;

            IntPtr ProcHandle = NativeMethods.OpenProcess(NativeMethods.ProcessAccess.AllAccess, false, Proc.Id);

            if (ProcHandle == IntPtr.Zero)
                return false;

            IntPtr cave = NativeMethods.VirtualAllocEx(ProcHandle, (IntPtr)0, (uint)DLLName.Length, 0x1000 | 0x2000, 0x04); // MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE. THIS Allocates Memory for the PATH of our Library as LoadLibraryA has one argument. We don't need the EXECUTE FLAG as it is just a text String.

            if (cave == IntPtr.Zero)
                return false;

            Boolean WPM = NativeMethods.WriteProcessMemory(ProcHandle, cave, DLLName, (uint)DLLName.Length, out bWritten);
            if (WPM == false)
                return false;

            IntPtr hThr = NativeMethods.CreateRemoteThread(ProcHandle, (IntPtr)0, (uint)0, LoadLib, cave, (uint)0, out hThread);

            if (hThr == IntPtr.Zero)
                return false;

            return true;
        }

		public LauncherForm()
		{
			this.InitializeComponent();
			this.languagesComboBox.SelectedValueChanged += new EventHandler(this.languagesComboBox_SelectedValueChanged);
			this.keyboardComboBox.SelectedValueChanged += new EventHandler(this.keyboardComboBox_SelectedValueChanged);
			this.CheckRegistry();
			this.settings.AddSetting("Keyboard", "", this.keyboardComboBox, null);
			string englishName = CultureInfo.CurrentUICulture.EnglishName;
			this.languages.Add("English", "ENG");
			this.languages.Add("French", "FRA");
			this.languages.Add("Italian", "ITA");
			this.languages.Add("German", "DEU");
			this.languages.Add("Spanish", "ESP");
			this.languages.Add("Russian", "RUS");
            this.languages.Add("Hungarian", "HUN");
			this.gamePatchStatusLabel.Visible = false;
			foreach (KeyValuePair<string, string> language in this.languages)
			{
				if (!CultureInfo.CurrentUICulture.EnglishName.Contains(language.Key))
				{
					continue;
				}
				englishName = language.Key;
			}
			this.GetKeyboardLayouts();
			this.settings.AddSetting("Language", englishName, this.languagesComboBox, null);
			this.optionsForm = new Options(this.settings);
			bool flag = false;
            Setting setting = this.settings.GetSetting("Language");
			foreach (KeyValuePair<string, string> keyValuePair in this.languages)
			{
				flag = flag | setting.AddValue(keyValuePair.Key);
			}
			if (!flag)
			{
				CultureInfo currentUICulture = CultureInfo.CurrentUICulture;
				int num = 0;
				foreach (KeyValuePair<string, string> possibleValue in setting.PossibleValues)
				{
					if (currentUICulture.EnglishName.IndexOf(possibleValue.Key) != -1)
					{
						break;
					}
					num++;
				}
				if (num >= this.languagesComboBox.Items.Count)
				{
					num = 0;
				}
				this.languagesComboBox.SelectedIndex = num;
			}
			setting.UpdateValue();
			if (this.languagesComboBox.Items.Count == 1)
			{
				this.languagesComboBox.Enabled = false;
			}
			if (this.keyboardComboBox.Items.Count == 1)
			{
				this.keyboardComboBox.Enabled = false;
			}
			if (!File.Exists(string.Concat(this.gameInstallDir, "\\LANoire.exe")))
			{
				this.versionLabel.Text = "";
				this.currentGameVersion = "";
			}
			else
			{
				FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(string.Concat(this.gameInstallDir, "\\LANoire.exe"));
				string comments = versionInfo.Comments;
				Label label = this.versionLabel;
				object[] productMajorPart = new object[] { "v", versionInfo.ProductMajorPart, ".", versionInfo.ProductMinorPart };
				label.Text = string.Concat(productMajorPart);
				this.currentGameVersion = versionInfo.FileVersion;
				int num1 = this.currentGameVersion.IndexOf(",");
				int num2 = this.currentGameVersion.IndexOf(",", num1 + 1);
				if (num2 > -1)
				{
					this.currentGameVersion = this.currentGameVersion.Substring(0, num2);
				}
				this.currentGameVersion = this.currentGameVersion.Replace(", ", ".");
			}
            this.versionLabel.Text = "0.1a";
			if (!File.Exists(string.Concat(this.socialClubInstallDir, "\\socialclub.dll")))
			{
				this.socialClubVersion = "";
			}
			else
			{
				FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(string.Concat(this.socialClubInstallDir, "\\socialclub.dll"));
				string str = fileVersionInfo.Comments;
				this.socialClubVersion = fileVersionInfo.FileVersion;
				this.socialClubVersion = this.socialClubVersion.Replace(", ", ".");
			}
			this.gamePatchStatusLabel.Visible = false;
			this.scPatchStatusLabel.Visible = false;
		}

		private int CheckAdminRights(bool _game)
		{
			if ((new WindowsPrincipal(WindowsIdentity.GetCurrent())).IsInRole(WindowsBuiltInRole.Administrator))
			{
				return 2;
			}
			object value = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", "EnableLUA", null);
			if (value == null)
			{
				if (!_game)
				{
					MessageBox.Show(StringLocaliser.LocaliseString("NEEDADMINTOINSTALL", false));
				}
				else
				{
					MessageBox.Show(StringLocaliser.LocaliseString("NEEDADMINTORUN", false));
				}
				return 1;
			}
			if ((int)value != 0)
			{
				return 1;
			}
			if (!_game)
			{
				MessageBox.Show(StringLocaliser.LocaliseString("NEEDADMINTOINSTALL", false));
			}
			else
			{
				MessageBox.Show(StringLocaliser.LocaliseString("NEEDADMINTORUN", false));
			}
			return 0;
		}

		private void CheckRegistry()
		{
			string str = "Software\\Valve\\Steam\\Apps\\110800";
			RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("Software\\Wow6432Node\\Valve\\Steam\\Apps\\110800") ?? Registry.LocalMachine.OpenSubKey(str);
			if (registryKey == null)
			{
				this.launchGameButton.Text = StringLocaliser.LocaliseString("INSTALLGAME", false);
				this.optionsButton.Enabled = false;
				this.optionsButton.ForeColor = Color.Gray;
				this.launchGameButtonInstallsGame = true;
			}
			else
			{
				object value = registryKey.GetValue("InstallDir");
				if (value != null)
				{
					this.gameInstallDir = value.ToString();
					this.launchGameButton.Text = StringLocaliser.LocaliseString("launchGameButton", false);
					this.optionsButton.Enabled = true;
					this.launchGameButtonInstallsGame = false;
				}
			}
			registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Rockstar Games\\Rockstar Games Social Club") ?? Registry.LocalMachine.OpenSubKey("SOFTWARE\\Rockstar Games\\Rockstar Games Social Club");
			if (registryKey != null)
			{
				object obj = registryKey.GetValue("InstallFolder");
				if (obj != null)
				{
					this.socialClubInstallDir = obj.ToString();
				}
			}
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}

		[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
		private static extern IntPtr GetForegroundWindow();

		[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
		private static extern IntPtr GetKeyboardLayout(int WindowsThreadProcessID);

		private void GetKeyboardLayouts()
		{
			int num;
			StringLocaliser.manualLocalisations.Clear();
			InputLanguageCollection installedInputLanguages = InputLanguage.InstalledInputLanguages;
			Setting setting = this.settings.GetSetting("Keyboard");
			if (setting == null)
			{
				this.settings.AddSetting("Keyboard", "", this.keyboardComboBox, null);
				setting = this.settings.GetSetting("Keyboard");
			}
			bool flag = false;
			setting.Clear();
			int windowThreadProcessId = LauncherForm.GetWindowThreadProcessId(LauncherForm.GetForegroundWindow(), out num);
			LauncherForm.GetKeyboardLayout(windowThreadProcessId);
			if (flag | setting.AddValue("UK") | setting.AddValue("US") | setting.AddValue("FR") | setting.AddValue("IT") | setting.AddValue("DE") | setting.AddValue("ES") | setting.AddValue("RU"))
			{
				ComboBox attachedControl = (ComboBox)setting.AttachedControl;
				attachedControl.SelectedIndex = 0;
				setting.WorkingValue = "UK";
				if (InputLanguage.CurrentInputLanguage.Culture.EnglishName == "English (United States)")
				{
					attachedControl.SelectedItem = StringLocaliser.LocaliseString("US", false);
					setting.WorkingValue = "US";
				}
				if (InputLanguage.CurrentInputLanguage.Culture.EnglishName == "English (United Kingdom)")
				{
					attachedControl.SelectedItem = StringLocaliser.LocaliseString("UK", false);
					setting.WorkingValue = "UK";
				}
				else if (InputLanguage.CurrentInputLanguage.Culture.EnglishName == "French (France)")
				{
					attachedControl.SelectedItem = StringLocaliser.LocaliseString("FR", false);
					setting.WorkingValue = "FR";
				}
				else if (InputLanguage.CurrentInputLanguage.Culture.EnglishName == "Italian (Italy)")
				{
					attachedControl.SelectedItem = StringLocaliser.LocaliseString("IT", false);
					setting.WorkingValue = "IT";
				}
				else if (InputLanguage.CurrentInputLanguage.Culture.EnglishName == "German (Germany)")
				{
					attachedControl.SelectedItem = StringLocaliser.LocaliseString("DE", false);
					setting.WorkingValue = "DE";
				}
				else if (InputLanguage.CurrentInputLanguage.Culture.EnglishName == "Spanish (Spain)")
				{
					attachedControl.SelectedItem = StringLocaliser.LocaliseString("ES", false);
					setting.WorkingValue = "ES";
				}
				if (InputLanguage.CurrentInputLanguage.Culture.EnglishName == "Russian (Russia)")
				{
					attachedControl.SelectedItem = StringLocaliser.LocaliseString("RU", false);
					setting.WorkingValue = "RU";
				}
			}
		}

		[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
		private static extern int GetWindowThreadProcessId(IntPtr handleWindow, out int lpdwProcessID);

		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LauncherForm));
            this.optionsButton = new System.Windows.Forms.Button();
            this.quitButton = new System.Windows.Forms.Button();
            this.languagesComboBox = new System.Windows.Forms.ComboBox();
            this.readmeButton = new System.Windows.Forms.Button();
            this.toolTip = new System.Windows.Forms.ToolTip(this.components);
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.launchGameButton = new System.Windows.Forms.Button();
            this.LANGUAGE = new System.Windows.Forms.Label();
            this.keyboardComboBox = new System.Windows.Forms.ComboBox();
            this.KEYBOARD = new System.Windows.Forms.Label();
            this.versionLabel = new System.Windows.Forms.Label();
            this.gamePatchStatusLabel = new System.Windows.Forms.Label();
            this.scPatchStatusLabel = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // optionsButton
            // 
            this.optionsButton.BackgroundImage = global::LANLauncher.Properties.Resources.Button;
            this.optionsButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            this.optionsButton.FlatAppearance.BorderColor = System.Drawing.Color.Black;
            this.optionsButton.FlatAppearance.MouseDownBackColor = System.Drawing.Color.White;
            this.optionsButton.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Red;
            this.optionsButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.optionsButton.ForeColor = System.Drawing.Color.White;
            this.optionsButton.Location = new System.Drawing.Point(270, 48);
            this.optionsButton.Name = "optionsButton";
            this.optionsButton.Size = new System.Drawing.Size(134, 30);
            this.optionsButton.TabIndex = 2;
            this.optionsButton.Text = "OPTIONS";
            this.optionsButton.UseVisualStyleBackColor = false;
            this.optionsButton.Click += new System.EventHandler(this.optionsButton_Click);
            // 
            // quitButton
            // 
            this.quitButton.BackgroundImage = global::LANLauncher.Properties.Resources.Button;
            this.quitButton.FlatAppearance.BorderColor = System.Drawing.Color.Black;
            this.quitButton.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Lime;
            this.quitButton.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Red;
            this.quitButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.quitButton.ForeColor = System.Drawing.Color.White;
            this.quitButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.quitButton.Location = new System.Drawing.Point(270, 120);
            this.quitButton.Name = "quitButton";
            this.quitButton.Size = new System.Drawing.Size(134, 30);
            this.quitButton.TabIndex = 4;
            this.quitButton.Text = "QUIT";
            this.quitButton.UseVisualStyleBackColor = true;
            this.quitButton.Click += new System.EventHandler(this.quitButton_Click);
            // 
            // languagesComboBox
            // 
            this.languagesComboBox.BackColor = System.Drawing.Color.DimGray;
            this.languagesComboBox.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.languagesComboBox.FormattingEnabled = true;
            this.languagesComboBox.Location = new System.Drawing.Point(12, 178);
            this.languagesComboBox.Name = "languagesComboBox";
            this.languagesComboBox.Size = new System.Drawing.Size(190, 21);
            this.languagesComboBox.TabIndex = 5;
            // 
            // readmeButton
            // 
            this.readmeButton.BackgroundImage = global::LANLauncher.Properties.Resources.Button;
            this.readmeButton.FlatAppearance.BorderColor = System.Drawing.Color.Black;
            this.readmeButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.readmeButton.ForeColor = System.Drawing.Color.White;
            this.readmeButton.Location = new System.Drawing.Point(270, 84);
            this.readmeButton.Name = "readmeButton";
            this.readmeButton.Size = new System.Drawing.Size(134, 30);
            this.readmeButton.TabIndex = 9;
            this.readmeButton.Text = "README";
            this.readmeButton.UseVisualStyleBackColor = true;
            this.readmeButton.Click += new System.EventHandler(this.readmeButton_Click);
            // 
            // toolTip
            // 
            this.toolTip.IsBalloon = true;
            // 
            // pictureBox1
            // 
            this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
            this.pictureBox1.Location = new System.Drawing.Point(12, 12);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(252, 134);
            this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.pictureBox1.TabIndex = 6;
            this.pictureBox1.TabStop = false;
            // 
            // launchGameButton
            // 
            this.launchGameButton.BackgroundImage = global::LANLauncher.Properties.Resources.Button;
            this.launchGameButton.FlatAppearance.BorderColor = System.Drawing.Color.Black;
            this.launchGameButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.launchGameButton.ForeColor = System.Drawing.Color.White;
            this.launchGameButton.Location = new System.Drawing.Point(270, 12);
            this.launchGameButton.Name = "launchGameButton";
            this.launchGameButton.Size = new System.Drawing.Size(134, 30);
            this.launchGameButton.TabIndex = 0;
            this.launchGameButton.Text = "LAUNCHGAME";
            this.launchGameButton.UseVisualStyleBackColor = true;
            this.launchGameButton.Click += new System.EventHandler(this.launchGameButton_Click);
            // 
            // LANGUAGE
            // 
            this.LANGUAGE.AutoSize = true;
            this.LANGUAGE.ForeColor = System.Drawing.Color.White;
            this.LANGUAGE.Location = new System.Drawing.Point(13, 162);
            this.LANGUAGE.Name = "LANGUAGE";
            this.LANGUAGE.Size = new System.Drawing.Size(66, 13);
            this.LANGUAGE.TabIndex = 11;
            this.LANGUAGE.Text = "LANGUAGE";
            // 
            // keyboardComboBox
            // 
            this.keyboardComboBox.BackColor = System.Drawing.Color.DimGray;
            this.keyboardComboBox.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.keyboardComboBox.FormattingEnabled = true;
            this.keyboardComboBox.Location = new System.Drawing.Point(214, 178);
            this.keyboardComboBox.Name = "keyboardComboBox";
            this.keyboardComboBox.Size = new System.Drawing.Size(190, 21);
            this.keyboardComboBox.TabIndex = 6;
            // 
            // KEYBOARD
            // 
            this.KEYBOARD.AutoSize = true;
            this.KEYBOARD.ForeColor = System.Drawing.Color.White;
            this.KEYBOARD.Location = new System.Drawing.Point(211, 162);
            this.KEYBOARD.Name = "KEYBOARD";
            this.KEYBOARD.Size = new System.Drawing.Size(66, 13);
            this.KEYBOARD.TabIndex = 12;
            this.KEYBOARD.Text = "KEYBOARD";
            // 
            // versionLabel
            // 
            this.versionLabel.Anchor = System.Windows.Forms.AnchorStyles.Top;
            this.versionLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.versionLabel.ForeColor = System.Drawing.Color.White;
            this.versionLabel.Location = new System.Drawing.Point(107, 113);
            this.versionLabel.Name = "versionLabel";
            this.versionLabel.Size = new System.Drawing.Size(60, 13);
            this.versionLabel.TabIndex = 13;
            this.versionLabel.Text = "label1";
            this.versionLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
            // 
            // gamePatchStatusLabel
            // 
            this.gamePatchStatusLabel.ForeColor = System.Drawing.Color.White;
            this.gamePatchStatusLabel.Location = new System.Drawing.Point(37, 129);
            this.gamePatchStatusLabel.Name = "gamePatchStatusLabel";
            this.gamePatchStatusLabel.Size = new System.Drawing.Size(200, 13);
            this.gamePatchStatusLabel.TabIndex = 14;
            this.gamePatchStatusLabel.Text = "label1";
            this.gamePatchStatusLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // scPatchStatusLabel
            // 
            this.scPatchStatusLabel.ForeColor = System.Drawing.Color.White;
            this.scPatchStatusLabel.Location = new System.Drawing.Point(37, 149);
            this.scPatchStatusLabel.Name = "scPatchStatusLabel";
            this.scPatchStatusLabel.Size = new System.Drawing.Size(200, 13);
            this.scPatchStatusLabel.TabIndex = 15;
            this.scPatchStatusLabel.Text = "label1";
            this.scPatchStatusLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // LauncherForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.Color.Black;
            this.ClientSize = new System.Drawing.Size(416, 212);
            this.ControlBox = false;
            this.Controls.Add(this.scPatchStatusLabel);
            this.Controls.Add(this.gamePatchStatusLabel);
            this.Controls.Add(this.versionLabel);
            this.Controls.Add(this.KEYBOARD);
            this.Controls.Add(this.keyboardComboBox);
            this.Controls.Add(this.LANGUAGE);
            this.Controls.Add(this.languagesComboBox);
            this.Controls.Add(this.readmeButton);
            this.Controls.Add(this.pictureBox1);
            this.Controls.Add(this.quitButton);
            this.Controls.Add(this.optionsButton);
            this.Controls.Add(this.launchGameButton);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "LauncherForm";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "L.A. Online";
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

		}

		private void keyboardComboBox_SelectedValueChanged(object sender, EventArgs e)
		{
			this.settings.SetSettingsNeedSaved();
		}

		private void languagesComboBox_SelectedValueChanged(object sender, EventArgs e)
		{
			if (this.suppress)
			{
				return;
			}
			int selectedIndex = this.languagesComboBox.SelectedIndex;
			Setting setting = this.settings.GetSetting("Language");
			string str = setting.DelocaliseValue(this.languagesComboBox.SelectedItem.ToString());
			foreach (KeyValuePair<string, string> language in this.languages)
			{
				if (str != language.Key)
				{
					continue;
				}
				setting.WorkingValue = language.Value;
				StringLocaliser.language = language.Value;
				this.LocaliseControl(this);
				if (!this.launchGameButtonInstallsGame)
				{
					this.launchGameButton.Text = StringLocaliser.LocaliseString("launchGameButton", false);
				}
				else
				{
					this.launchGameButton.Text = StringLocaliser.LocaliseString("INSTALLGAME", false);
				}
				this.settings.LocaliseSettings();
				this.settings.SetSettingsNeedSaved();
				this.suppress = true;
				this.languagesComboBox.SelectedIndex = selectedIndex;
				this.suppress = false;
				return;
			}
		}

		private void launchGameButton_Click(object sender, EventArgs e)
		{
			if (this.launchGameButtonInstallsGame)
			{
				if (!File.Exists("setup.exe"))
				{
					MessageBox.Show(StringLocaliser.LocaliseString("SETUPMISSING", false));
					base.Close();
				}
				int num = this.CheckAdminRights(false);
				if (num == 0)
				{
					return;
				}
				ProcessStartInfo processStartInfo = new ProcessStartInfo()
				{
					UseShellExecute = true,
					FileName = "setup.exe"
				};
				if (num == 1)
				{
					processStartInfo.Verb = "runas";
				}
				try
				{
					Process.Start(processStartInfo);
				}
				catch (Exception exception)
				{
				}
				base.Close();
				return;
			}
			this.settings.SaveToFile();
			if (!File.Exists(string.Concat(this.gameInstallDir, "\\LANoire.exe")))
			{
				MessageBox.Show(StringLocaliser.LocaliseString("EXEMISSING", false));
				return;
			}
			int num1 = this.CheckAdminRights(true);
			if (num1 == 0)
			{
				return;
			}
			Setting setting = this.settings.GetSetting("Command Line");
			ProcessStartInfo value = new ProcessStartInfo()
			{
				UseShellExecute = true,
				FileName = string.Concat(this.gameInstallDir, "\\LANoire.exe"),
				WorkingDirectory = this.gameInstallDir
			};
			if (num1 == 1)
			{
				value.Verb = "runas";
			}
			value.Arguments = setting.Value;
			Process process = null;
			try
			{
				if (this.patchCheckThread != null)
				{
					this.patchCheckThread.Abort();
				}
				process = Process.Start(value);
			}
			catch (Exception exception1)
			{
			}
			if (process != null)
			{
				ProcessStartInfo processStartInfo1 = new ProcessStartInfo()
				{
					FileName = string.Concat(this.gameInstallDir, "\\LAOnline.exe"),
					Arguments = "-SplashScreen Loading"
				};
                InjectDLL("LAOnline.dll", Process.Start(processStartInfo1));
                
			}
			base.Close();
		}

		private void LocaliseControl(Control _control)
		{
			StringLocaliser.LocaliseString(string.Concat(_control.Name, "_TT"), false);
			if (_control is ComboBox)
			{
				return;
			}
			if (_control.Name != "versionLabel")
			{
				_control.Text = StringLocaliser.LocaliseString(_control.Name, true);
			}
			foreach (Control control in _control.Controls)
			{
				this.LocaliseControl(control);
			}
		}

		private void optionsButton_Click(object sender, EventArgs e)
		{
			this.optionsForm.ShowDialog();
			this.commandlineArgs = this.optionsForm.GetCommandLine();
		}

		private void quitButton_Click(object sender, EventArgs e)
		{
			this.settings.SaveToFile();
			base.Close();
		}

		private void readmeButton_Click(object sender, EventArgs e)
		{
			string str = "Readme.txt";
			this.languagesComboBox.SelectedItem.ToString();
			Setting setting = this.settings.GetSetting("Language");
			if (setting.WorkingValue.Contains("English"))
			{
				str = "ReadmeENG.txt";
			}
			else if (setting.WorkingValue.Contains("French"))
			{
				str = "ReadmeFRA.txt";
			}
			else if (setting.WorkingValue.Contains("Italian"))
			{
				str = "ReadmeITA.txt";
			}
			else if (setting.WorkingValue.Contains("German"))
			{
				str = "ReadmeDEU.txt";
			}
			else if (setting.WorkingValue.Contains("Spanish"))
			{
				str = "ReadmeESP.txt";
			}
			else if (setting.WorkingValue.Contains("Russian"))
			{
				str = "ReadmeRUS.txt";
			}
			if (File.Exists(string.Concat(this.gameInstallDir, "\\", str)))
			{
				Process.Start(string.Concat(this.gameInstallDir, "\\", str));
				return;
			}
			if (File.Exists(str))
			{
				Process.Start(str);
				return;
			}
			if (File.Exists("Readme.txt"))
			{
				Process.Start("Readme.txt");
			}
		}

		private void rockstarWebsiteButton_Click(object sender, EventArgs e)
		{
			Process.Start("http://www.rockstargames.com");
		}

		private void saveFolderButton_Click(object sender, EventArgs e)
		{
			string str = string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "\\L.A. Noire");
			if (Directory.Exists(str))
			{
				Process.Start("explorer.exe", str);
			}
		}

		private void SetPatchCheckStrings(string gameText, string scText)
		{
			if (!this.gamePatchStatusLabel.InvokeRequired && !this.launchGameButton.InvokeRequired && !this.scPatchStatusLabel.InvokeRequired)
			{
				this.gamePatchStatusLabel.Text = string.Concat("L.A. Noire: ", gameText);
				this.scPatchStatusLabel.Text = string.Concat("Social Club: ", scText);
				this.launchGameButton.Enabled = true;
				return;
			}
			LauncherForm.SetPatchCheckCallback setPatchCheckCallback = new LauncherForm.SetPatchCheckCallback(this.SetPatchCheckStrings);
			object[] objArray = new object[] { gameText, scText };
			base.Invoke(setPatchCheckCallback, objArray);
		}

		private delegate void SetPatchCheckCallback(string gameText, string scText);
	}
}